<% var js = { %>
<script>
	$(function() {
		function loadData(){
			var search={"key":$("#txtKey").val()};
			core.exgrid({
				id:'table',
				obj:'page',
				search:search,
				checkbox:true,
				rownumber:true,
				size:10,
				pagesize:[10,20,50],
				index:1,
				pager:"page",
				key:"id",
				columns: [
		            {
		                field: "id",
		                title: "ID",
		                hidden:true
		            },
		            {
		                field: "name",
		                title: "角色名称"
		            },
		            {
		                field: "code",
		                title: "角色代码"
		            },
		            {
		                field: "status",
		                title: "状态",
		                align:"center",
		                formatter: function (v) {
		                    return v ? "启用" : "锁定";
		                }
		            }
				],
				btnContainer:"toolbar",
				buttonCodes:"${btnCodes}",
				buttons:[
					{
						name:"新增",
						type:"nomal",
						code:"btnAdd",
						callback:function(){
							core.frame({
								title:'新增',
								btns:[ '确认', '取消' ],
								area:[ '600px', '580px' ],
								url:'detail',
								success:function(index, layero){
									var form=layer.getChildFrame('form', index);
									if(form.find("#name").val()==""){
										layer.alert('角色名称不能为空');
										form.find("#name").focus();
										return false;
									}
									var model={"id":form.find("#id").val()};
									model.name=form.find("#name").val();
									model.code=form.find("#code").val();
									model.status=form.find("#status").val();
									model.menuIds=form.find("#menuIds").val();
									model.btnIds=form.find("#btnIds").val();
									var loadIndex = layer.load();//加载层
									$.post("save",model,function(result){
										layer.close(loadIndex);
										if(result.flag){
											layer.alert("新增成功");
											loadData();
											layer.close(index);
										}else{
											layer.alert(result.msg==null?"新增失败":result.msg);
										}
									});
								}
							});
						}
					},
					{
						name:"修改",
						type:"nomal",
						code:"btnUpdate",
						callback:function(){
							var ids=coreui.getSelectIds("table");
							if(ids.length==0){
								layer.alert("请选择要修改的数据");
								return false;
							}
							if(ids.length>1){
								layer.alert("只能选择一条数据修改");
								return false;
							}
							core.frame({
								title:'修改',
								btns:[ '确认', '取消' ],
								area:[ '600px', '580px' ],
								url:'detail?id='+ids[0],
								success:function(index, layero){
									var form=layer.getChildFrame('form', index);
									if(form.find("#name").val()==""){
										layer.alert('角色名称不能为空');
										form.find("#name").focus();
										return false;
									}
									var model={"id":form.find("#id").val()};
									model.name=form.find("#name").val();
									model.code=form.find("#code").val();
									model.status=form.find("#status").val();
									model.menuIds=form.find("#menuIds").val();
									model.btnIds=form.find("#btnIds").val();
									var loadIndex = layer.load();//加载层
									$.post("save",model,function(result){
										layer.close(loadIndex);
										if(result.flag){
											layer.alert("修改成功");
											loadData();
											layer.close(index);
										}else{
											layer.alert(result.msg==null?"修改失败":result.msg);
										}
									});
								}
							});
						}
					},
					{
						name:"删除",
						type:"del",
						code:"btnDelete",
						callback:function(){
							var ids=coreui.getSelectIds("table");
							if(ids.length==0){
								layer.alert("请选择要删除的数据");
								return false;
							}
							layer.confirm('删除后不能恢复，确认删除？', {icon: 3, title:'提示'}, function(index){
								var loadIndex = layer.load();//加载层
								$.post("delete",{"ids":ids},function(result){
									layer.close(loadIndex);
									if(result.flag){
										layer.alert("删除成功");
										loadData();
									}else{
										layer.alert(result.msg==null?"删除失败":result.msg);
									}
								});
								layer.close(index);
							});
						}
					}
				]
			});
		}
		loadData();
		$("#btnRefresh").click(function() {
			loadData();
		});
		$("#btnSearch").click(function() {
			loadData();
		});
	});
</script>
<% }; %> 
<% layout("/beetl/common/_layout.html",{title:"系统用户管理",js:js}){%>
<div class="main-container">
	<div class="box box-default box-radius">
		<div id="toolbar" class="box-head">
			角色名称： <input id="txtKey" type="text" class="form-input" placeholder="角色名称" />
			<button id="btnSearch" class="btn btn-bg-green">搜索</button>
			<button id="btnRefresh" class="btn btn-bg-green">刷新</button>
		</div>
		<table id="table" class="box-body"></table>
		<div class="box-foot">
			<div id="page" class="box-footer"></div>
		</div>
	</div>
</div>
<% } %>








